﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;

public partial class terminate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ((AfterLogin)this.Master).mainCategory = "ACCOUNTS";
        for (int i = 0; i < gvAcc.Rows.Count; i++)
        {
            string stat = gvAcc.Rows[i].Cells[1].Text;


            if (stat.Equals("Terminated"))
            {
                gvAcc.Rows[i].Cells[7].Visible = false;

            }

        }
       
    }
    protected void gvAcc_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "withdraw")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            GridViewRow row = gvAcc.Rows[index];
            string accNo = row.Cells[0].Text;
            string status = row.Cells[1].Text;



            string strConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            SqlConnection myConnection = new SqlConnection(strConnectionString);

            myConnection = DBManager.getSqlConnection();
            SqlCommand myCommandc = new SqlCommand("UPDATE FIXED_DEPOSIT SET status = '" + "Terminating" + "', withdrawDate = '" + DateTime.Now + "' WHERE [accountNo] = " + accNo, myConnection);
            myConnection.Open();
            myCommandc.ExecuteNonQuery();

            myConnection.Close();

            Response.Redirect("terminate.aspx");



            //for (int i = 0; i < gvAcc.Rows.Count; i++)
            //{
            //    string stat = gvAcc.Rows[i].Cells[1].Text;


            //    if (stat.Equals("Terminated"))
            //    {
            //        gvAcc.Rows[i].Cells[7].Enabled = false;

            //    }

            //}

            
        }
    }
   
}